const state = {
	introduces: [],
	tutorials: [],
	forumData: [],

}

const getters = {
	// 获取指定id的论坛帖子数据
	getForumId(state) {
		return (id) => {
			const filter = state.forumData.filter(item => item.forumId == id)[0];
			// console.log(`指定id=${ id }数据：${JSON.stringify(filter)}`)
			return filter
		}
	},
	// 获取指定id的介绍数据
	getIntroduceId(state) {
		return (id) => {
			const filter = state.introduces.filter(item => item.introduceId == id)[0];
			// console.log(`指定id=${ id }数据：${JSON.stringify(filter)}`)
			return filter
		}
	},
	// 获取指定id的教程数据
	getTutorialsId(state) {
		return (id) => {
			const filter = state.tutorials.filter(item => item.tutorialsId == id)[0];
			// console.log(id, typeof(filter.tutorialsId))
			return filter
		}
	},
}

const mutations = {
	//获取论坛帖子数据
	getForumData(state) {
		uni.request({
			url: 'http://localhost:3000/users/forumData',
			method: 'get',
			data: {},
			success: (res) => {
				state.forumData = res.data
				console.log("获取数据：", res);
			},
			fail: (res) => {
				console.log(res)
			}
		})
	},
	//获取介绍数据
	getIntroduces(state) {
		uni.request({
			url: 'http://localhost:3000/course',
			method: 'get',
			data: {
				type: "introduce"
			},
			success: (res) => {
				state.introduces = res.data
				// console.log(res);
			},
			fail: (res) => {
				console.log(res)
			}
		})
	},
	//获取教程数据
	getTutorials() {
		uni.request({
			url: 'http://localhost:3000/course',
			method: 'get',
			data: {
				type: "tutorials"
			},
			success: (res) => {
				state.tutorials = res.data
				console.log(res);
			},
			fail: (res) => {
				console.log(res)
			}
		})
	},

}

const actions = {}

export default {
	namespaced: true,
	state,
	getters,
	mutations,
	actions,
}